package com.nhjf.mobile.controller.collection;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nhjf.common.page.Pagination;
import com.nhjf.common.util.StringUtil;
import com.nhjf.mobile.common.util.SysProperties;
import com.nhjf.model.coursesSeries.CoursesSeries;
import com.nhjf.model.system.AdminSession;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.ArtPictures;
import com.nhjf.model.teachers.ArtPicturesCollection;
import com.nhjf.model.teachers.Courses;
import com.nhjf.model.teachers.CoursesCollection;
import com.nhjf.model.teachers.ReviewPainting;
import com.nhjf.model.teachers.ReviewPaintingCollection;
import com.nhjf.model.teachers.Teacher;
import com.nhjf.pojo.dto.collection.CollectionDto;
import com.nhjf.pojo.qo.system.AdminSessionQo;
import com.nhjf.pojo.qo.system.UserQo;
import com.nhjf.pojo.qo.teachers.ArtPicturesCollectionQo;
import com.nhjf.pojo.qo.teachers.ArtPicturesQo;
import com.nhjf.pojo.qo.teachers.CoursesCollectionQo;
import com.nhjf.pojo.qo.teachers.CoursesCommentQo;
import com.nhjf.pojo.qo.teachers.CoursesQo;
import com.nhjf.pojo.qo.teachers.ReviewPaintingCollectionQo;
import com.nhjf.pojo.qo.teachers.ReviewPaintingQo;
import com.nhjf.pojo.qo.teachers.TeachersQo;
import com.nhjf.service.coursesSeries.CoursesSeriesService;
import com.nhjf.service.system.AdminSessionService;
import com.nhjf.service.system.UserService;
import com.nhjf.service.teachers.ArtPicturesCollectionService;
import com.nhjf.service.teachers.ArtPicturesService;
import com.nhjf.service.teachers.CoursesCollectionService;
import com.nhjf.service.teachers.CoursesService;
import com.nhjf.service.teachers.ReviewPaintingCollectionService;
import com.nhjf.service.teachers.ReviewPaintingService;
import com.nhjf.service.teachers.TeachersService;

import net.sf.json.JSONObject;

@RequestMapping("/collection")
@Controller
public class collectionController {

	@Autowired
	private ArtPicturesCollectionService artPicturesCollectionService;
	@Autowired
	private CoursesCollectionService coursesCollectionService;
	@Autowired
	private ReviewPaintingCollectionService reviewPaintingCollectionService;
	@Autowired
	private AdminSessionService adminSessionService;
	@Autowired
	private UserService userService;
	@Autowired
	private TeachersService teachersService;
	@Autowired
	private ArtPicturesService artPicturesService;

	@Autowired
	private CoursesSeriesService coursesSeriesService;
	@Autowired
	private ReviewPaintingService reviewPaintingService;
	/**
	 * 收藏作品
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param artPicturesid
	 * @return
	 */
	@RequestMapping("/collection_artPictures")
	@ResponseBody
	public String collectionArt(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,String artPicturesid) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		AdminSession adminSession=new AdminSession();
		AdminSessionQo adminSessionQo=new AdminSessionQo();
		adminSessionQo.setToken(token);
		adminSession=adminSessionService.queryUnique(adminSessionQo);
		if(adminSession==null) {
			resMap.put("code", "406");
			resMap.put("message", "不存在此账号！");
			return JSONObject.fromObject(resMap).toString();
		}else {
			try {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}
				else {
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					if(teacher!=null) {
						ArtPictures artPictures= artPicturesService.get(Long.parseLong(artPicturesid));
						if(artPictures==null) {
							resMap.put("code", "500");
							resMap.put("message", "未找到此课程！");
							return JSONObject.fromObject(resMap).toString();
						}else {
							ArtPicturesCollectionQo artPicturesCollectionQo=new ArtPicturesCollectionQo();
							artPicturesCollectionQo.setUserId(user.getId());
							artPicturesCollectionQo.setArtPicturesId(Long.parseLong(artPicturesid));
							ArtPicturesCollection artPicturesCollection1= artPicturesCollectionService.queryUnique(artPicturesCollectionQo);
							if(artPicturesCollection1==null) {
								ArtPicturesCollection  artPicturesCollection=new ArtPicturesCollection();
								artPicturesCollection.setArtPictures(artPictures);
								artPicturesCollection.setUser(user);
								artPicturesCollection.setCollectionUserType(1);
								artPicturesCollection.setCollectionTime(new Date());
								ArtPicturesCollection artPicturesCollection2= artPicturesCollectionService.save(artPicturesCollection);
								if(artPicturesCollection2!=null) {
									resMap.put("code", "200");
									resMap.put("message", "成功！");
									return JSONObject.fromObject(resMap).toString();
								}else {
									resMap.put("code", "500");
									resMap.put("message", "失败！");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {
								resMap.put("code", "500");
								resMap.put("message", "已收藏！");
								return JSONObject.fromObject(resMap).toString();
							}

						}
					}else {
						ArtPictures artPictures= artPicturesService.get(Long.parseLong(artPicturesid));
						if(artPictures==null) {
							resMap.put("code", "500");
							resMap.put("message", "失败！");
							return JSONObject.fromObject(resMap).toString();
						}else {
							ArtPicturesCollectionQo artPicturesCollectionQo=new ArtPicturesCollectionQo();
							artPicturesCollectionQo.setArtPicturesId(Long.parseLong(artPicturesid));
							artPicturesCollectionQo.setUserId(user.getId());
							ArtPicturesCollection artPicturesCollection1= artPicturesCollectionService.queryUnique(artPicturesCollectionQo);
							if(artPicturesCollection1==null) {
								ArtPicturesCollection  artPicturesCollection=new ArtPicturesCollection();
								artPicturesCollection.setArtPictures(artPictures);
								artPicturesCollection.setUser(user);
								artPicturesCollection.setCollectionUserType(2);
								artPicturesCollection.setCollectionTime(new Date());
								ArtPicturesCollection artPicturesCollection2=artPicturesCollectionService.save(artPicturesCollection);
								if(artPicturesCollection2!=null) {
									resMap.put("code", "200");
									resMap.put("message", "成功！");
									return JSONObject.fromObject(resMap).toString();
								}else {
									resMap.put("code", "500");
									resMap.put("message", "失败！");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {
								resMap.put("code", "500");
								resMap.put("message", "已收藏！");
								return JSONObject.fromObject(resMap).toString();
							}
						}
					}
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				resMap.put("code", "500");
				resMap.put("message", "系统异常！");
				return JSONObject.fromObject(resMap).toString();
			}
		}
	}
	/**
	 * 收藏课程
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param coursesid
	 * @return
	 */
	@RequestMapping("/collection_courses") 
	@ResponseBody
	public String collectionCou(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,String coursesid) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					if(teacher!=null) {
						CoursesSeries courses=coursesSeriesService.get(Long.parseLong(coursesid));
						if(courses==null) {
							resMap.put("code", "404");
							resMap.put("message", "未找到此课程!");
							return JSONObject.fromObject(resMap).toString();
						}else {
							CoursesCollectionQo coursesCollectionQo=new CoursesCollectionQo();
							coursesCollectionQo.setUserId(user.getId());
							coursesCollectionQo.setCoursesId(Long.parseLong(coursesid));
							CoursesCollection collection1=coursesCollectionService.queryUnique(coursesCollectionQo);
							if(collection1==null) {
								CoursesCollection collection=new CoursesCollection();
								collection.setCollectionUserType(1);
								collection.setCoursesId(courses);
								collection.setCollectionTime(new Date());
								collection.setUserId(user);
								CoursesCollection collection2=coursesCollectionService.save(collection);
								if(collection2!=null) {
									resMap.put("code", "200");
									resMap.put("message", "成功！");
									return JSONObject.fromObject(resMap).toString();
								}else {
									resMap.put("code", "500");
									resMap.put("message", "失败！");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {
								resMap.put("code", "500");
								resMap.put("message", "此课程已存在!");
								return JSONObject.fromObject(resMap).toString();
							}

						}

					}else {
						CoursesSeries courses=coursesSeriesService.get(Long.parseLong(coursesid));
						if(courses==null) {
							resMap.put("code", "404");
							resMap.put("message", "未找到此课程!");
							return JSONObject.fromObject(resMap).toString();
						}else {
							CoursesCollectionQo coursesCollectionQo=new CoursesCollectionQo();
							coursesCollectionQo.setUserId(user.getId());
							coursesCollectionQo.setCoursesId(Long.parseLong(coursesid));
							CoursesCollection collection1=coursesCollectionService.queryUnique(coursesCollectionQo);
							if(collection1==null) {
								CoursesCollection collection=new CoursesCollection();
								collection.setCollectionUserType(2);
								collection.setCoursesId(courses);
								collection.setCollectionTime(new Date());
								collection.setUserId(user);
								CoursesCollection collection2=coursesCollectionService.save(collection);
								if(collection2!=null) {
									resMap.put("code", "200");
									resMap.put("message", "成功！");
									return JSONObject.fromObject(resMap).toString();
								}else {
									resMap.put("code", "500");
									resMap.put("message", "失败！");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {
								resMap.put("code", "500");
								resMap.put("message", "此课程已经存在！");
								return JSONObject.fromObject(resMap).toString();
							}

						}

					}
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "失败！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 收藏改画
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param reviewid
	 * @return
	 */
	@RequestMapping("/collection_review")
	@ResponseBody
	public String collectionReview(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,String reviewid) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}
				else {
					TeachersQo teachersQo=new TeachersQo();
					teachersQo.setUserId(user.getId());
					Teacher teacher= teachersService.queryUnique(teachersQo);
					if(teacher!=null) {
						ReviewPainting reviewPainting= reviewPaintingService.get(Long.parseLong(reviewid));
						if(reviewPainting==null) {
							resMap.put("code", "404");
							resMap.put("message", "未找到此改画！");
							return JSONObject.fromObject(resMap).toString();
						}else {
							ReviewPaintingCollectionQo paintingCollectionQo=new ReviewPaintingCollectionQo();
							paintingCollectionQo.setUserId(user.getId());
							paintingCollectionQo.setReviewPaintingid(Long.parseLong(reviewid));
							ReviewPaintingCollection collection= reviewPaintingCollectionService.queryUnique(paintingCollectionQo);
							if(collection==null) {
								ReviewPaintingCollection reviewPaintingCollection=new ReviewPaintingCollection();
								reviewPaintingCollection.setUserId(user);
								reviewPaintingCollection.setCollectionUserType(1);
								reviewPaintingCollection.setCollectionTime(new Date());
								reviewPaintingCollection.setReviewPaintingId(reviewPainting);
								ReviewPaintingCollection reviewPaintingCollection2=reviewPaintingCollectionService.save(reviewPaintingCollection);
								if(reviewPaintingCollection2!=null) {
									resMap.put("code", "200");
									resMap.put("message", "成功！");
									return JSONObject.fromObject(resMap).toString();
								}else {
									resMap.put("code", "500");
									resMap.put("message", "失败！");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {
								resMap.put("code", "500");
								resMap.put("message", "此改画已经存在！");
								return JSONObject.fromObject(resMap).toString();
							}

						}
					}else {
						ReviewPainting reviewPainting= reviewPaintingService.get(Long.parseLong(reviewid));
						if(reviewPainting==null) {
							resMap.put("code", "500");
							resMap.put("message", "未找到！");
							return JSONObject.fromObject(resMap).toString();
						}else {
							ReviewPaintingCollectionQo paintingCollectionQo=new ReviewPaintingCollectionQo();
							paintingCollectionQo.setUserId(user.getId());
							paintingCollectionQo.setReviewPaintingid(Long.parseLong(reviewid));
							ReviewPaintingCollection collection= reviewPaintingCollectionService.queryUnique(paintingCollectionQo);
							if(collection==null) {
								ReviewPaintingCollection reviewPaintingCollection=new ReviewPaintingCollection();
								reviewPaintingCollection.setUserId(user);
								reviewPaintingCollection.setCollectionUserType(2);
								reviewPaintingCollection.setCollectionTime(new Date());
								reviewPaintingCollection.setReviewPaintingId(reviewPainting);
								ReviewPaintingCollection reviewPaintingCollection2=reviewPaintingCollectionService.save(reviewPaintingCollection);
								if(reviewPaintingCollection2!=null) {
									resMap.put("code", "200");
									resMap.put("message", "成功！");
									return JSONObject.fromObject(resMap).toString();
								}else {
									resMap.put("code", "500");
									resMap.put("message", "失败！");
									return JSONObject.fromObject(resMap).toString();
								}
							}else {
								resMap.put("code", "500");
								resMap.put("message", "此改画已经存在！");
								return JSONObject.fromObject(resMap).toString();
							}

						}


					}
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "失败！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 收藏作品列表
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param coursesId
	 * @param page
	 * @return
	 */
	@RequestMapping("/collection_art_List")
	@ResponseBody
	public String collectionArtList(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}
				else {
					
					ArtPicturesCollectionQo artPicturesCollectionQo=new ArtPicturesCollectionQo();
					artPicturesCollectionQo.setUserId(user.getId());
					artPicturesCollectionQo.setSeachArtPictures(true);
					Pagination pagination = new Pagination();
					pagination.setPageSize(10);
					pagination.setCondition(artPicturesCollectionQo);
					pagination.setPageNo(page);
					pagination = artPicturesCollectionService.queryPagination(pagination);
					List<ArtPicturesCollection> alist=(List<ArtPicturesCollection>)pagination.getList();
					SysProperties sysProperties=SysProperties.getInstance();
					String imagePath=sysProperties.get("imagePath");
					for (ArtPicturesCollection artPicturesCollection : alist) {
						if(StringUtils.isNotEmpty(artPicturesCollection.getArtPictures().getArtPicturesUrl())) {
							artPicturesCollection.getArtPictures().setArtPicturesUrl(imagePath+"/artPictures/"+artPicturesCollection.getArtPictures().getArtPicturesUrl());
						}
						
					}
					resMap.put("code", "200");
					resMap.put("message", pagination);
					return JSONObject.fromObject(resMap).toString();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 收藏课程列表
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param coursesId
	 * @param page
	 * @return
	 */
	@RequestMapping("/collection_Courses_List")
	@ResponseBody
	public String collectionCoursesList(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}
				else {
					CoursesCollectionQo coursesCollectionQo=new CoursesCollectionQo();
					coursesCollectionQo.setSeachCourses(true);
					coursesCollectionQo.setUserId(user.getId());
					Pagination pagination = new Pagination();
					pagination.setPageSize(10);
					pagination.setCondition(coursesCollectionQo);
					pagination.setPageNo(page);
					pagination = coursesCollectionService.queryPagination(pagination);
					List<CoursesCollection> clist=(List<CoursesCollection>)pagination.getList();
					SysProperties sysProperties=SysProperties.getInstance();
					String imagePath=sysProperties.get("imagePath");
					for (CoursesCollection coursesCollection : clist) {
						if(StringUtils.isNotEmpty(coursesCollection.getCoursesId().getCover())) {
							coursesCollection.getCoursesId().setCover(imagePath+"/img/"+coursesCollection.getCoursesId().getCover());
						}
						
					}
					resMap.put("code", "200");
					resMap.put("message", pagination);
					return JSONObject.fromObject(resMap).toString();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 收藏改画列表
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param coursesId
	 * @param page
	 * @return
	 */
	@RequestMapping("/collection_reviewPaint_List")
	@ResponseBody
	public String collectionReviewPaintList(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}
				else {
					ReviewPaintingCollectionQo reviewPaintingCollectionQo=new ReviewPaintingCollectionQo();
					reviewPaintingCollectionQo.setSeachReviewPainting(true);
					reviewPaintingCollectionQo.setUserId(user.getId());
					Pagination pagination = new Pagination();
					pagination.setPageSize(10);
					pagination.setCondition(reviewPaintingCollectionQo);
					pagination.setPageNo(page);
					pagination = reviewPaintingCollectionService.queryPagination(pagination);
					List<ReviewPaintingCollection> rlist=(List<ReviewPaintingCollection>)pagination.getList();
					SysProperties sysProperties=SysProperties.getInstance();
					String imagePath=sysProperties.get("imagePath");
					for (ReviewPaintingCollection reviewPaintingCollection : rlist) {
						if(StringUtils.isNotEmpty(reviewPaintingCollection.getReviewPaintingId().getChangepaintingURL())) {
							reviewPaintingCollection.getReviewPaintingId().setChangepaintingURL(imagePath+"/reviewPainting/"+reviewPaintingCollection.getReviewPaintingId().getChangepaintingURL());
						}
						
					}
					resMap.put("code", "200");
					resMap.put("message", pagination);
					return JSONObject.fromObject(resMap).toString();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 查看当前登陆用户收藏信息
	 * @param request
	 * @param response
	 * @param model
	 * @param token
	 * @param coursesId
	 * @param page
	 * @return
	 */
	@RequestMapping("/collection_Type")
	@ResponseBody
	public String collectionType(HttpServletRequest request, HttpServletResponse response, Model model,
			@RequestParam(value="token", required=true)String  token,@RequestParam(value = "page", defaultValue = "1")Integer page) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}
				else {
					CollectionDto collectionDto=new CollectionDto();
					ArtPicturesCollectionQo artPicturesCollectionQo=new ArtPicturesCollectionQo();
					CoursesCollectionQo coursesCollectionQo=new CoursesCollectionQo();
					ReviewPaintingCollectionQo reviewPaintingCollectionQo=new ReviewPaintingCollectionQo();
					artPicturesCollectionQo.setUserId(user.getId());
					coursesCollectionQo.setUserId(user.getId());
					reviewPaintingCollectionQo.setUserId(user.getId());
					artPicturesCollectionQo.setSeachArtPictures(true);
					artPicturesCollectionQo.setSeachUser(true);
					Pagination pagination = new Pagination();
					pagination.setPageSize(10);
					pagination.setCondition(artPicturesCollectionQo);
					pagination.setPageNo(page);
					pagination = artPicturesCollectionService.queryPagination(pagination);
					List<ArtPicturesCollection> alist=(List<ArtPicturesCollection>)pagination.getList();
					for (ArtPicturesCollection artPicturesCollection : alist) {
						if(artPicturesCollection.getUser()!=null) {
							artPicturesCollection.getUser().setUserPassword("");
						}
						
					}
					collectionDto.setAlist(alist);
					coursesCollectionQo.setSeachCourses(true);
					coursesCollectionQo.setSeachUser(true);
					Pagination pagination1 = new Pagination();
					pagination1.setPageSize(10);
					pagination1.setCondition(coursesCollectionQo);
					pagination1.setPageNo(page);
					pagination1 = coursesCollectionService.queryPagination(pagination1);
					List<CoursesCollection> clist=(List<CoursesCollection>)pagination1.getList();
					collectionDto.setClist(clist);


					reviewPaintingCollectionQo.setSeachReviewPainting(true);
					reviewPaintingCollectionQo.setSeachUser(true);
					Pagination pagination2 = new Pagination();
					pagination2.setPageSize(10);
					pagination2.setCondition(reviewPaintingCollectionQo);
					pagination2.setPageNo(page);
					pagination2 = reviewPaintingCollectionService.queryPagination(pagination2);
					List<ReviewPaintingCollection> rlist=(List<ReviewPaintingCollection>)pagination2.getList();
					
					for (ReviewPaintingCollection reviewPaintingCollection : rlist) {
						if(reviewPaintingCollection.getUserId()!=null) {
							reviewPaintingCollection.getUserId().setUserPassword("");
						}
						
						
					}
					collectionDto.setRlist(rlist);
					resMap.put("code", "200");
					resMap.put("message", collectionDto);
					return JSONObject.fromObject(resMap).toString();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常！");
			return JSONObject.fromObject(resMap).toString();
		}
	}
	/**
	 * 取消收藏作品
	 * @param token
	 * @param artPicturesid
	 * @return
	 */
	@RequestMapping("/unsubscribe_artPictures")
	@ResponseBody
	public String unsubscribeArtPictures(@RequestParam(value="token", required=true)String  token,String artPicturesid) {
		Map<String, Object> resMap=new HashMap<String, Object>();

		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					ArtPicturesCollectionQo artPicturesCollectionQo=new ArtPicturesCollectionQo();
					artPicturesCollectionQo.setArtPicturesId(Long.parseLong(artPicturesid));
					artPicturesCollectionQo.setUserId(user.getId());
					ArtPicturesCollection artPicturesCollection= artPicturesCollectionService.queryUnique(artPicturesCollectionQo);
					if(artPicturesCollection!=null) {
						artPicturesCollectionService.deleteById(artPicturesCollection.getId());
						resMap.put("code", "200");
						resMap.put("message", "取消成功!");
						return JSONObject.fromObject(resMap).toString();
					}else {
						resMap.put("code", "500");
						resMap.put("message", "没有找到!");
						return JSONObject.fromObject(resMap).toString();
					}


				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}

	}
	/**
	 * 取消收藏课程
	 * @param token
	 * @param coursesId
	 * @return
	 */
	@RequestMapping("/unsubscribe_courses")
	@ResponseBody
	public String unsubscribeCourses(@RequestParam(value="token", required=true)String  token,String coursesId) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					CoursesCollectionQo coursesCollectionQo=new CoursesCollectionQo();
					coursesCollectionQo.setCoursesId(Long.parseLong(coursesId));
					coursesCollectionQo.setUserId(user.getId());
					CoursesCollection coursesCollection= coursesCollectionService.queryUnique(coursesCollectionQo);
					if(coursesCollection!=null) {
						coursesCollectionService.deleteById(coursesCollection.getId());
						resMap.put("code", "200");
						resMap.put("message", "取消成功!");
						return JSONObject.fromObject(resMap).toString();
					}else {
						resMap.put("code", "500");
						resMap.put("message", "没有找到!");
						return JSONObject.fromObject(resMap).toString();
					}
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}
		
	}
	/**
	 * 取消收藏改画
	 * @param token
	 * @param reviewPaintingid
	 * @return
	 */
	@RequestMapping("/unsubscribe_reviewPainting")
	@ResponseBody
	public String unsubscribeReviewPainting(@RequestParam(value="token", required=true)String  token,String reviewPaintingid) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		try {
			AdminSession adminSession=new AdminSession();
			AdminSessionQo adminSessionQo=new AdminSessionQo();
			adminSessionQo.setToken(token);
			adminSession=adminSessionService.queryUnique(adminSessionQo);
			if(adminSession==null) {
				resMap.put("code", "406");
				resMap.put("message", "不存在此账号！");
				return JSONObject.fromObject(resMap).toString();
			}else {
				adminSession.getLoginName();
				UserQo userQo=new UserQo();
				userQo.setUserName(adminSession.getLoginName());
				User user= userService.queryUnique(userQo);
				if(user==null) {
					resMap.put("code", "406");
					resMap.put("message", "未登录!");
					return JSONObject.fromObject(resMap).toString();
				}else {
					ReviewPaintingCollectionQo paintingCollectionQo=new ReviewPaintingCollectionQo();
					paintingCollectionQo.setReviewPaintingid(Long.parseLong(reviewPaintingid));
					paintingCollectionQo.setUserId(user.getId());
					ReviewPaintingCollection reviewPaintingCollection= reviewPaintingCollectionService.queryUnique(paintingCollectionQo);
					if(reviewPaintingCollection!=null) {
						reviewPaintingCollectionService.deleteById(reviewPaintingCollection.getId());
						resMap.put("code", "200");
						resMap.put("message", "取消成功!");
						return JSONObject.fromObject(resMap).toString();
					}else {
						resMap.put("code", "500");
						resMap.put("message", "没有找到!");
						return JSONObject.fromObject(resMap).toString();
					}
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			resMap.put("code", "500");
			resMap.put("message", "系统异常!");
			return JSONObject.fromObject(resMap).toString();
		}
	}
}
